package com.rd.student.jike.class4.xiayinyin.week04.day25;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class TestExecutor {
    private static final int CORE_POOL_SIZE = 5;//核心线程的数量
    private static final int MAX_POOL_SIZE = 10;//线程池的最大线程数
    private static final int QUEUE_CAPACITY = 2;//等待队列
    private static final Long KEEP_ALIVE_TIME = 1L;//非核心线程存活的最长时间

    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                CORE_POOL_SIZE,
                MAX_POOL_SIZE,
                KEEP_ALIVE_TIME,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(QUEUE_CAPACITY),
                new ThreadPoolExecutor.AbortPolicy());

        for (int i = 0; i < 20; i++) {
            MyRunnable runnable = new MyRunnable();
            executor.execute(runnable);
        }
//        //终止
//        executor.shutdown();
//        System.out.println("finished");
    }
}
